<template>
  <div class="cart">
    <header>
      <div class="left" @click="onClickLeft">
        <van-icon name="arrow-left" size="20" color="#fff" />
      </div>
      <h2>购物车</h2>
      <div class="right"></div>
    </header>
    <div class="notice">
      <van-notice-bar left-icon="volume-o" :scrollable="false">
        <van-swipe
          vertical
          class="notice-swipe"
          :autoplay="3000"
          :show-indicators="false"
        >
          <van-swipe-item v-for="item in 3" :key="item">
            <div class="notice-title">
              <span class="left">专区满赠</span>
              <p>新品上新赠送试饮装</p>
              <span class="right">
                去看看
                <van-icon name="arrow" />
              </span>
            </div>
          </van-swipe-item>
        </van-swipe>
      </van-notice-bar>
    </div>
    <Section v-if="!show"/>
    <section v-if="show">
      <div class="blank">
        <van-icon name="bag-o" size="140" color="#ddd" />
        <p class="txt">您的购物车空荡荡的，你可以</p>
        <p class="btn">
          返回　
          <span>首页</span>
        </p>
      </div>
      <div class="main">
        <div class="title">
          <van-icon name="goods-collect-o" color="#3ec234"  size="22"/>
          <span>为您推荐</span>
        </div>
        <div class="list">
          <ul>
            <li v-for="item in billList" :key="item.id">
              <div class="img">
                <img :src="item.imgUrl" alt="" />
                <span class="tip"> {{ item.tip }} </span>
              </div>
              <p class="txt">{{ item.title }}</p>
              <p class="price">
                <span
                  ><i>{{ item.price }}</i
                  >元</span
                >
                <em v-if="item.stutes">
                  <i class="el-icon-s-shop"></i> 约{{ item.unit }}元/斤
                </em>
              </p>
            </li>
          </ul>
        </div>
      </div>
    </section>
    <Tabbar v-if="show"/>

  </div>
</template>

<script>
import Section from '@/components/cart/Section.vue'
import Tabbar from "@/components/common/Tabbar.vue";
import { getBill} from "@/utils/api/api";
export default {
  data() {
    return {
      billList: [],
    };
  },
  computed:{
    show() {
      return this.$store.state.cartList.length == 0
    }
  },
  components: {
    Tabbar,
    Section
  },
  beforeMount() {
    getBill().then((res) => {
      this.billList = res.data.data.data[0].billData;
    });
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onClickRight() {},
  },
};
</script>

<style lang="less" scoped>
.cart {
  background-color: #f5f5f5;
  header {
    display: flex;
    align-items: center;
    background: #b0352f;
    height: 44px;
    color: #fff;
    div {
      width: 44px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    h2 {
      flex: 1;
      text-align: center;
      font-size: 16px;
      font-weight: 400;
    }
  }
  .notice {
    .notice-swipe {
      height: 40px;
      line-height: 40px;
    }
    .notice-title {
      display: flex;
      align-items: center;
      .left {
        background: #e4393c;
        color: #fff;
        font-size: 12px;
        padding: 0 5px;
        height: 18px;
        line-height: 18px;
        margin-right: 5px;
        vertical-align: top;
        text-align: center;
        border-radius: 3px;
      }
      p {
        flex: 1;
        width: 100%;
        margin-right: 60px;
      }
      .right {
        position: relative;
        font-size: 14px;
        color: #999;
        line-height: 35px;
      }
    }
  }
  section {
    padding-bottom: 60px;
    .blank {
      color: #9e9e9e;
      margin-top: 30px;
      padding: 0 30px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      font-size: 14px;
      .btn {
        color: #9e9e9e;
        margin: 20px 0;
        span {
          line-height: 35px;
          padding: 10px 25px;
          background: #b0352f;
          color: #fff;
          border-radius: 3px;
        }
      }
    }
    .main {
      .title {
        border-bottom: 1px #f5f5f5 solid;
        padding: 20px;
        font-size: 16px;
        background: #fff;
        display: flex;
        align-items: center;
        span {
          margin-left: 5px;
        }
      }
      .list {
        ul {
          display: flex;
          justify-content: space-between;
          flex-wrap: wrap;
          background: #f5f5f5;
          li {
            box-sizing: border-box;
            background: #fff;
            width: 49.9%;
            padding: 11px;
            margin-bottom: 7.5px;
            .img {
              width: 100%;
              position: relative;
              img {
                width: 100%;
              }
              .tip {
                position: absolute;
                bottom: 0;
                left: -11px;
                background: rgba(0, 0, 0, 0.4);
                font-size: 12px;
                color: #fff;
                width: 100%;
                padding: 4px 10px;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              }
            }
            .txt {
              font-size: 14px;
              color: #333;
              line-height: 30px;
              padding: 6px 0;
              // height: 30px;
              overflow: hidden;
              box-sizing: border-box;
              -webkit-line-clamp: 2;
              -webkit-box-orient: vertical;
            }
            .price {
              display: flex;
              justify-content: space-between;
              span {
                color: #ff6600;
                font-size: 14px;
                i {
                  font-size: 18px;
                }
              }
              em {
                color: #999999;
                font-size: 12px;
                padding: 5px 5px 0;
                i {
                  font-size: 14px;
                  padding-right: 3px;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>